#include <assert.h>
#include <stdio.h>

#include "../src/estep.c"

typedef struct _EStepTestDatum EStepTestDatum;
struct _EStepTestDatum
{ 
  struct
    {
      float    loga[6 * 4];
      float    gamma[6];
      float    logbeta[3];
      float    c[6 * 5];
      float    d[6 * 5];
      float    priorz[5];
      int       clamp[3];
      Rating    ratings[8];
    }                   inputs;

  float pz[3 * 5];
};

static void
test_estep (void)
{
  EStepTestDatum data[] = 
    {{{{0.48786676470877144, 0.8185978377729255, 0.12918514015792773, 0.9684359998727491, 0.32398107748805155, 0.14905991560927026, 0.3633008512802759, 0.9426618658088497, 0.13541221083159224, 0.989002790673122, 0.19134066092273835, 0.39235786440575954, 0.6495422776700399, 0.8214345566218559, 0.03794969043996477, 0.841323267405312, 0.28324600919595333, 0.34399467106540876, 0.9023272872884283, 0.3377028079708985, 0.38945205507925484, 0.46158236070458086, 0.7836502502979682, 0.5219489023595352}, {0.9015852903704834, 0.6429845229316554, 0.6544651101400405, 0.5535129024867861, 0.5776042128824319, 0.49392460732238513}, {0.2911642588597646, 0.6108510366779364, 0.4421920020508396}, {0.5049218166492632, 0.09982359793702626, 0.21849317227217685, 0.7926497243807996, 0.6834872600274072, 0.061873907497061495, 0.3771699048668648, 0.5094037151848464, 0.33949258896199846, 0.15954662020863322, 0.0394670968959663, 0.11995166010559152, 0.8779102282574176, 0.375896369910665, 0.5175181945364311, 0.21836636973510812, 0.2349257053257622, 0.7214312597706245, 0.964005292049645, 0.6407621568526762, 0.7410010980033771, 0.43026700091085984, 0.3531542553717087, 0.19857015480183665, 0.23607928135411388, 0.33044340297383357, 0.13466108309953184, 0.405920430421037, 0.5525920213267067, 0.2685694954767721}, {0.757491178232667, 0.8965167152361907, 0.21309943236470819, 0.10902287526813885, 0.7180240813367007, 0.7765650551305991, 0.3351892041072906, 0.7331265053574738, 0.20050588680026957, 0.558198685395491, 0.10026349878152839, 0.011695245586849388, 0.2365005947506245, 0.9174365285428148, 0.35926240077815136, 0.5814282446759895, 0.8833463393789158, 0.7188663737409781, 0.12318311942403744, 0.25098484170215596, 0.748685256279384, 0.3129459433199411, 0.5705910980973308, 0.9824153462253838, 0.991194078046717, 0.41642922808375044, 0.3574916657326226, 0.873392470957245, 0.27316999671001624, 0.6398641729531513}, {0.02230246162533199, 0.14026596559977114, 0.07266410990974667, 0.08166548755766032, 0.9220389628438036}, {-1, 4, -1}, {{0, 2, 1}, {0, 0, 3}, {1, 2, 1}, {3, 0, 1}, {2, 1, 2}, {2, 1, 1}, {3, 2, 2}, {1, 1, 0}}}, {0.006688578360861274, 0.8256756989899368, 0.010416466007173568, 0.028376005415419462, 0.1288432512266089, 0.003934101046685749, 0.0041352199958845735, 0.00010840718202306561, 6.5627392394701134e-9, 0.9918222652126676, 0.0004993669300746749, 0.9965245443689329, 0.002254722145648262, 5.793560031145025e-7, 0.0007207871993410956}},{{{0.5627765620656523, 0.5471424753369322, 0.9528171757802063, 0.4453625852738675, 0.4395934426416148, 0.29615763363477626, 0.20413191950082238, 0.1324166419539264, 0.869002344544284, 0.3137422874093924, 0.21293784145410544, 0.715987413870176, 0.5115106788116615, 0.4403498164521474, 0.9397678447440891, 0.07612324091702466, 0.48920821718632945, 0.3000838508523762, 0.8671037348343426, 0.9944577533593644, 0.5671692543425259, 0.17151313083945446, 0.030940219675220346, 0.8302287943445188}, {0.004392692276873593, 0.6243706555025222, 0.078123043895014, 0.3848662090706513, 0.5647992496352587, 0.328213021867746}, {0.8739911243941916, 0.25244956711672484, 0.6957969050909747}, {0.014470734458353587, 0.6610532829400861, 0.5364621532465489, 0.1842862262793133, 0.5741209180062062, 0.721285438195997, 0.4603389123295242, 0.6950780090929838, 0.27403706715382997, 0.8541817033616544, 0.46588115897015986, 0.12790875475045796, 0.10252393631437551, 0.8232414836864341, 0.6356523646256411, 0.12351606247358438, 0.47815328081185327, 0.7451184397914201, 0.25078615555498984, 0.5587168128383256, 0.14994025894410729, 0.8711273153972285, 0.998336588438265, 0.8629199077473508, 0.1354695244857537, 0.21007403245714235, 0.46187443519171617, 0.6786336814680376, 0.5613486064795475, 0.48878859426114535}, {0.001535522862191954, 0.9835556723750537, 0.2873115393257175, 0.6346068908994908, 0.5356543638920321, 0.8556469176245958, 0.184787603011342, 0.8113654072130567, 0.900001999266391, 0.7321308551510114, 0.7066343221994887, 0.06624696742163655, 0.6492158437114012, 0.1734140423126858, 0.5566940632553814, 0.195119652024408, 0.6508792552731362, 0.3104941345653349, 0.42122453876962773, 0.9850456195672657, 0.18900482008142003, 0.6318604530972973, 0.8598759322900803, 0.4962570253061203, 0.18746929721922806, 0.6483047807222436, 0.5725643929643628, 0.8616501344066294, 0.651814933327196, 0.7926578630976479}, {0.38777678995302073, 0.050284727193572736, 0.751812934060805, 0.06052700794663641, 0.681142467753532}, {4, -1, 1}, {{3, 2, 3}, {0, 1, 3}, {1, 1, 0}, {2, 1, 4}, {2, 0, 0}, {3, 0, 1}, {2, 2, 0}, {2, 0, 0}}}, {0.9894715843284408, 0.006004619964651327, 5.81833562546279e-8, 2.3319612062919604e-7, 0.004523504327430949, 0.7252813413388949, 0.0029659549493073816, 0.0048956970803703, 0.03439320621341072, 0.23246380041801662, 0.00045309724054883797, 0.9991732552616203, 1.430262115806309e-7, 0.0003734513570748506, 5.3114544397982907e-8}},{{{0.12444840449815056, 0.7889181077475281, 0.4517178350762676, 0.5766188310686157, 0.7032238657285228, 0.8038724881802625, 0.2627130149948476, 0.9447583779713183, 0.8433479334384426, 0.3076154628741422, 0.07524371777561954, 0.2964535972490747, 0.2707835404740798, 0.4459653284675128, 0.4234287844484236, 0.503795734151427, 0.883006750521059, 0.39568060127394006, 0.6716158503876186, 0.4432687262047905, 0.20186428276752705, 0.41164284150200386, 0.5690187600382148, 0.5561557605708399}, {0.07741587826937647, 0.6227247337544757, 0.11730092496194724, 0.9795369295022243, 0.37419201254085366, 0.8188522455742132}, {0.8545879099670997, 0.0347785515309059, 0.530844079102411}, {0.511236782700071, 0.7793441921914801, 0.7383249542818312, 0.2600605386283313, 0.06527145423255817, 0.3559154077430565, 0.23452922013040423, 0.37705378810727225, 0.6695908529586181, 0.6842995573554379, 0.7912604939256137, 0.1751895053397452, 0.2579480114566143, 0.11528079731722302, 0.2351047333547738, 0.09777362707036871, 0.6352232777021386, 0.9979798723552757, 0.25556780385254957, 0.7235816145295151, 0.8163710321279254, 0.14339196238817614, 0.22078925232164368, 0.19273753542710395, 0.30513424942785444, 0.36404777019669604, 0.4824642980398125, 0.9326769967987727, 0.23986279519529627, 0.008132362453639538}, {0.24793507790940827, 0.5556232086915004, 0.5702719422366781, 0.32383280509820167, 0.45667458398379457, 0.38043370335175525, 0.3123239307800639, 0.20855200778097863, 0.22156985062902076, 0.2826600762813865, 0.6771006530779253, 0.21057213542570286, 0.9660020467764712, 0.5590784617518715, 0.8607296209499999, 0.06718017303752671, 0.7452127944548275, 0.3663409263247675, 0.5555953715221456, 0.7031324028408307, 0.26274849641501496, 0.43366392952599486, 0.31573257632684926, 0.6950000403871911, 0.014813418505606678, 0.8780407208344944, 0.7454606340901712, 0.3711672352889895, 0.5581388345218121, 0.49760701748273917}, {0.43313670331010723, 0.16261522750801083, 0.33656898389279133, 0.21494694120135263, 0.7560360502321819}, {4, -1, 1}, {{1, 0, 2}, {1, 0, 3}, {0, 2, 2}, {1, 1, 2}, {2, 0, 2}, {2, 0, 4}, {3, 2, 1}, {1, 0, 1}}}, {5.744470701839152e-12, 2.579185793129404e-7, 1.4565325488523448e-8, 0.00003100412455865614, 0.9999687233857921, 0.03955649545290256, 0.038442862667640736, 0.6284829543287124, 0.07643322167861609, 0.2170844658721283, 1.9754128780080946e-8, 0.9999991342164265, 1.6046147841601304e-7, 4.399074338204993e-7, 2.456605325030659e-7}},{{{0.895306429282182, 0.8848629190447812, 0.6253541426614927, 0.2895275531247137, 0.33971105776003646, 0.1817305162039506, 0.36260564624647773, 0.8558636235987188, 0.02397848143318718, 0.4867304758167595, 0.34779222774087104, 0.9778229027642245, 0.27851784734301605, 0.11556324052777002, 0.7896533932190589, 0.4802158852814853, 0.8453811440329088, 0.9529480130197592, 0.4530844093262676, 0.26526894408013263, 0.0893450938007269, 0.0009049209374512365, 0.0825174722099474, 0.6094004646306515}, {0.19403866451854493, 0.11604200189266999, 0.45716332954845473, 0.31987291150593783, 0.8543276067585085, 0.9343114856887194}, {0.09455768330197699, 0.46400928790721896, 0.8303491253253213}, {0.4475810098719599, 0.746765455561106, 0.48618638514299456, 0.5518312779823052, 0.33201776934418986, 0.957112062342047, 0.00597049986150929, 0.7064501339493965, 0.3790697563244307, 0.5040276530157795, 0.7407015557813766, 0.6171050401486695, 0.3781648353869794, 0.421510180805832, 0.1313010911507252, 0.4230663756301246, 0.2621228334943095, 0.9643468512573773, 0.8114281796447874, 0.5687387688716161, 0.32781134780559007, 0.8697891679554003, 0.3474188917375684, 0.7383896435462948, 0.8802303379336301, 0.12302371239429437, 0.8612325065945738, 0.18655836556398958, 0.5482125685894403, 0.16591165005224737}, {0.8552620067330645, 0.48010823161459315, 0.16914281226500963, 0.6618839970364679, 0.1145604509516879, 0.8630031914659235, 0.7909779768780302, 0.24037381623063592, 0.9832593598009627, 0.43993681583579897, 0.5288551433837207, 0.2760269649732586, 0.17183118015617532, 0.8711980469641828, 0.20104379557813065, 0.40623779701785834, 0.8244122884186069, 0.132808403417888, 0.3208134576445005, 0.28321408462356396, 0.9631797818240331, 0.9462500378538984, 0.7726008890550602, 0.11730243457131657, 0.1079177750909685, 0.4661418062393053, 0.6034580767900506, 0.4554184375348486, 0.9933573241392806, 0.6031386147733817}, {0.8124800999120203, 0.2150446213042127, 0.010097964338317878, 0.16320179893758277, 0.2836249565282996}, {0, 4, -1}, {{1, 2, 1}, {0, 0, 4}, {1, 0, 3}, {0, 0, 2}, {2, 2, 4}, {2, 1, 2}, {2, 0, 1}, {2, 1, 2}}}, {0.9997738486353949, 0.00010465868026767032, 0.000024114422935788672, 0.000045303214294091894, 0.00005207504710754761, 0.0000175878861002812, 1.612265243297596e-7, 0.0022173566691732205, 7.679569417546951e-7, 0.9977641262612604, 0.0055436003254752475, 0.9377054416238996, 0.000030843339856194594, 0.00007996427346118438, 0.056640150437307746}},{{{0.08258116095016897, 0.5327798593130958, 0.013854495763535634, 0.15919534855551196, 0.7617677033056685, 0.24956577468953184, 0.05067471393950257, 0.21294531070161352, 0.9891668142506084, 0.13226334011821525, 0.9427569388485341, 0.7468035044623083, 0.3857087374605578, 0.6768449025833666, 0.9493996147092535, 0.1436648896889265, 0.5732286375485375, 0.4618002812791539, 0.9393016503709356, 0.9804630907513437, 0.2896036810202378, 0.5227826249481998, 0.10103486618879305, 0.6884593387779437}, {0.20702252007006886, 0.990002765635104, 0.08718037042525742, 0.5292639902224319, 0.4452548167644004, 0.7404369909455722}, {0.036505656485754844, 0.3163186795208183, 0.45608800251379206}, {0.608173650827357, 0.09374871763722077, 0.5695151750585101, 0.07037926505323423, 0.9313287482439904, 0.1443491029279673, 0.4258502853695836, 0.4971506275046968, 0.46952846696483647, 0.2050474525570317, 0.4453871946182399, 0.20754694648445896, 0.9467458420166367, 0.10401258636823865, 0.7569278558402961, 0.0005244264143900957, 0.9567430763815326, 0.016832215942981236, 0.2276638656178643, 0.5552696096499897, 0.2163060854359604, 0.9803265594572264, 0.911345186097046, 0.0991816071361977, 0.6081324346086034, 0.8865778418200057, 0.34183001103853594, 0.028802342082963468, 0.6768036863646131, 0.7422287388920383}, {0.9159797256689524, 0.5316517145782667, 0.20727521939977658, 0.5371812863350066, 0.4705925310507124, 0.3241047680938077, 0.2605293773831399, 0.433168699966768, 0.7136646752104163, 0.3235803416794176, 0.3037863010016073, 0.41633648402378676, 0.48600080959255204, 0.7683107320294279, 0.08748021556564695, 0.43600992456656035, 0.574655623495506, 0.6691291248932302, 0.47934778095704356, 0.5494320827465548, 0.2328256124569701, 0.6403267828102667, 0.8025440945924305, 0.8072033438545164, 0.3168458867880178, 0.10867506823200004, 0.5952688751926539, 0.27002205751950975, 0.8462533557373053, 0.7845703001381923}, {0.33473949780951395, 0.8368533575527418, 0.13258868052688902, 0.4609899584587747, 0.030953196807906636}, {-1, 1, 3}, {{0, 2, 4}, {1, 2, 2}, {0, 2, 3}, {3, 1, 4}, {3, 2, 4}, {0, 1, 4}, {2, 0, 0}, {3, 1, 2}}}, {0.4925447202774064, 0.27391009264040306, 0.021265589810223244, 0.2084109855098801, 0.003868611762087344, 0.00001990078848562704, 0.9982041907810765, 0.0006128548721392764, 0.00002896845501595469, 0.001134085103282734, 3.018463976532865e-8, 2.804088817594627e-10, 4.6399211566129324e-7, 0.9999992766831696, 2.2885966610631826e-7}},{{{0.9434729812422596, 0.9845069489623947, 0.07193224743883099, 0.023550101536116606, 0.46412520028521614, 0.43507486621583996, 0.8391066349818609, 0.38322331872584986, 0.6615811056927857, 0.6278715223613236, 0.5222607481938432, 0.27454825049384984, 0.06631223050013177, 0.3578494648418138, 0.6760073924565377, 0.4899779503556575, 0.7315727326906178, 0.520996107289072, 0.5434187119296487, 0.028987991896882826, 0.7006195358827112, 0.10047923376011696, 0.8968308409953117, 0.336308765467536}, {0.7571465546404514, 0.11597228479772226, 0.8248985935564808, 0.31275866393141943, 0.2930213543552353, 0.6808974185818822}, {0.9857919585746199, 0.9295353452055696, 0.6314402486624496}, {0.053025896220558734, 0.4635312103807767, 0.6549870947117197, 0.5651280181623178, 0.695176431378745, 0.787523817924239, 0.16500914435606218, 0.8335552854717001, 0.17418032408967296, 0.2441051059945902, 0.13602115245917934, 0.13293574958898893, 0.07370109032955599, 0.34727426499927844, 0.7997123869916434, 0.37578919494853746, 0.9577288055318337, 0.5223756714427977, 0.4869537230602239, 0.08276784059330214, 0.27683138694995146, 0.5365837128681779, 0.5574183778546543, 0.4513275919308525, 0.2238054907293927, 0.07305250248740111, 0.9024312831429346, 0.8861995737685346, 0.5286290593506477, 0.28552868456316216}, {0.7374221387868725, 0.0526442882968345, 0.3544487352609748, 0.04142357856857197, 0.6014009863276931, 0.9197085387078455, 0.2807476449314188, 0.6941493135692935, 0.8016885993360499, 0.5439193437593081, 0.3230188393995851, 0.17177364212649582, 0.3147348762758259, 0.46115150316600595, 0.04618745244963363, 0.635189929258318, 0.7573164984211715, 0.009823911235153486, 0.8223819617202409, 0.5621374267709168, 0.8548852152782369, 0.1236243374666189, 0.29375290236959317, 0.2766087422077547, 0.11746307649136438, 0.0709800491697844, 0.9393041671086183, 0.23518516363918274, 0.5160620901636712, 0.15127151046193882}, {0.6585565221771995, 0.5410358500698892, 0.7143734908276215, 0.6073521667026307, 0.3355376827776145}, {-1, -1, -1}, {{1, 2, 1}, {0, 2, 0}, {2, 0, 4}, {0, 1, 4}, {1, 0, 1}, {0, 1, 4}, {3, 2, 3}, {2, 0, 0}}}, {0.9175933224387112, 0.0024885160038030274, 6.872789757642964e-7, 0.00031488526231145624, 0.07960258901619847, 0.0009465533272719709, 0.0001842992993075944, 1.5419392076011222e-6, 0.0005253405711136041, 0.9983422648630992, 0.9406762819417622, 0.012654336540883411, 7.760352976947249e-6, 0.041531021648514965, 0.005130599515862497}},{{{0.2893502303279808, 0.7340722786850754, 0.642322116130624, 0.13637675230147128, 0.4669682686077399, 0.17193485191415855, 0.7874369008523872, 0.012752414834852375, 0.17321536623814673, 0.8953261097064038, 0.6699738243610227, 0.941772365665068, 0.23391119912952837, 0.6601409460672212, 0.1539117341973515, 0.7905008552031292, 0.5753546769523289, 0.11910509599733192, 0.43953824336973, 0.18314868850049842, 0.2398169941747144, 0.7498428880539385, 0.03989962881793451, 0.036948024963873664}, {0.9504667638467336, 0.015770609368863125, 0.3975775126873105, 0.9005712726624024, 0.4834984952389937, 0.8438357574547046}, {0.6101406118349234, 0.88781885782755, 0.310283129000847}, {0.9485096477483007, 0.9401667874739007, 0.946046492162482, 0.07637192987131859, 0.2883687016810796, 0.7862550532765492, 0.1555456369593529, 0.5010172529189897, 0.16926360568374765, 0.34671680990681913, 0.9723969484588545, 0.2612002587442753, 0.4194207176298091, 0.3068171810888846, 0.9354489234949808, 0.31073349489754176, 0.403650108260946, 0.9092396684015741, 0.034877650832578426, 0.8272349996585481, 0.5598143508062414, 0.2990990565666507, 0.14705879300502842, 0.5169518706577011, 0.6113047030579407, 0.35893226909275006, 0.20101230084254637, 0.4405799407863825, 0.3229360013768611, 0.5726772158162009}, {0.04546666388319347, 0.9395626878673928, 0.15367239569311347, 0.22596040590938174, 0.07306971542433899, 0.6783624291231174, 0.7342516780633044, 0.9191432248204972, 0.13762079192935817, 0.3676289342255757, 0.3306015698023584, 0.009903556418923012, 0.10274314109677975, 0.5403939345670277, 0.7707872189961169, 0.7108044998522723, 0.9556843480917513, 0.023442063909326512, 0.15948251593817625, 0.35187223075952223, 0.754672047249205, 0.5828621231229439, 0.8365465145613151, 0.7791950149433213, 0.7092053833660115, 0.6432994352555512, 0.6828741188682017, 0.5532346090339396, 0.6361356679416725, 0.9649370061324337}, {0.9486224408048973, 0.6340913842134425, 0.49851487601231437, 0.5973080719068581, 0.618020871002539}, {3, -1, -1}, {{3, 2, 4}, {0, 0, 1}, {3, 1, 4}, {3, 0, 0}, {2, 0, 3}, {1, 0, 0}, {1, 1, 3}, {0, 2, 3}}}, {1.695351006802701e-7, 8.947416677733196e-7, 2.4016985416003437e-11, 0.9999989356970364, 2.178210768100594e-12, 0.00011705854330495443, 0.02015783332263587, 0.0008753078812582015, 0.9632904224229369, 0.015559377829864086, 0.013797899667358931, 0.11863855026757417, 0.042635733257779196, 0.5912413590007293, 0.2336864578065585}},{{{0.847233652006422, 0.9133833279422472, 0.4400873868237833, 0.033472073430503964, 0.6877511360682458, 0.561511097182725, 0.6854153395745783, 0.45060995030755996, 0.8512046215069307, 0.7823160822394036, 0.9762099562085668, 0.8073105150520088, 0.16833050263872895, 0.22908147320546396, 0.34007428826689423, 0.842373508919575, 0.21970806183383165, 0.5949900889920214, 0.8415594122545799, 0.2450654370127169, 0.6016871908312927, 0.970802261197502, 0.4457876773390453, 0.18815129967288644}, {0.7544535388248707, 0.05741893325525477, 0.005700290515262017, 0.15467922624238245, 0.06670240275662495, 0.4959078360725298}, {0.3202849509406837, 0.7040692759348225, 0.21549778124969432}, {0.7135917538331262, 0.34407499473211695, 0.8967587608828137, 0.04716727861096536, 0.48451028062766227, 0.0040007064652227, 0.05438525196323875, 0.8274592167771337, 0.8895201916356408, 0.1624412942106428, 0.8093198149505219, 0.22577202594584103, 0.9187179304381389, 0.7166536168715976, 0.6211685152776354, 0.4713184871209703, 0.861298997182884, 0.7109533263563355, 0.46648928903525294, 0.4046160843643454, 0.36539116111035425, 0.3906683754156518, 0.7624200131004305, 0.18911830311465105, 0.6517994072772281, 0.04659338068353483, 0.8656612522176167, 0.14195102450368569, 0.16728912664956574, 0.04259267421831212}, {0.811276000254378, 0.314491807726552, 0.2777689350139249, 0.8801513800076693, 0.0019561853038561347, 0.08871978178071095, 0.3590510045757861, 0.16349776313607178, 0.3807876700262207, 0.6174012946597406, 0.497752007392902, 0.45254443677973627, 0.9142983809909677, 0.21278521029539527, 0.1323608462825477, 0.061876061364084516, 0.15187836789053727, 0.023666907180744205, 0.48056143900531967, 0.015282680680549688, 0.2862171156729205, 0.8817158826770585, 0.3132723123557539, 0.9726900064622376, 0.47494111541854256, 0.5672240749505065, 0.03550337734182901, 0.09253862645456824, 0.4729849301146864, 0.4785042931697956}, {0.676452372766043, 0.9290408633184964, 0.0921972600884657, 0.861102998510055, 0.17870036537314096}, {-1, -1, 2}, {{2, 0, 3}, {1, 1, 0}, {3, 0, 3}, {3, 1, 4}, {2, 1, 0}, {3, 2, 0}, {3, 0, 2}, {3, 1, 2}}}, {0.00044905897044662145, 0.001177498894852227, 0.000036938887121835976, 0.9979197225698198, 0.00041678067775957985, 0.9842180246642852, 0.0022182233839296954, 0.000036698064070401254, 0.009867253150708275, 0.003659800737006523, 0.00008771604055747643, 9.618264523448952e-6, 0.9998704828955772, 0.000021102948906976157, 0.00001107985043492069}},{{{0.04633951909059324, 0.41462036517467565, 0.026020511206960695, 0.6246508810339155, 0.5657780800852735, 0.39933768449412593, 0.7398033955340402, 0.742934998356857, 0.2525057677295196, 0.4266476780318884, 0.2648622801154976, 0.17571092340635044, 0.2170023903876906, 0.3341090515773201, 0.7918773500008112, 0.6972066302365548, 0.5405500176216477, 0.4050681882588237, 0.6996800899123455, 0.8361036317264998, 0.3618496522485067, 0.9285717617200635, 0.5217812108148475, 0.18778584351184016}, {0.3155101331579135, 0.5139513965453879, 0.4957606996078869, 0.5631349624779246, 0.7497320530726399, 0.11461371205126196}, {0.7559573040738466, 0.8201999641210677, 0.4972262853431203}, {0.6879660340193736, 0.4910950239583491, 0.6444890407147172, 0.2802238949554297, 0.35385698244205344, 0.6992176739575379, 0.9472824104781624, 0.7396738773337821, 0.9487887941832297, 0.9995375840451923, 0.11117877875166252, 0.37782422508527536, 0.020217032463166168, 0.4777563732303448, 0.9233929352398224, 0.06231409192736189, 0.5062656359177783, 0.981995673622458, 0.3602579727618977, 0.31258203885472197, 0.3916519238665163, 0.22603836954861126, 0.54005800864083, 0.8153557535116017, 0.7036858898471428, 0.7349433455902622, 0.8955689679261128, 0.535131858556172, 0.3498289074050893, 0.03572567163272432}, {0.9482865574479504, 0.7954579812223899, 0.4010401132218596, 0.03618808758753197, 0.8371077786962878, 0.41763375613711456, 0.3808230807586934, 0.5584317143571872, 0.9137148434564655, 0.3553196642097527, 0.8745574448409151, 0.5764360407347292, 0.5534568706945678, 0.042737625355030694, 0.48290552097439887, 0.350397671186118, 0.013398862053737783, 0.227381871843429, 0.7792196311272561, 0.6154543255958558, 0.11782989412762498, 0.692250013287257, 0.4293907237221668, 0.5797286539631314, 0.16954333667967458, 0.8967920320648671, 0.0283506105003072, 0.5435405663755996, 0.3324355579833867, 0.47915827592775256}, {0.6475275297416138, 0.9851088520184124, 0.41872071452692117, 0.1238386117179999, 0.7729700849006985}, {-1, 2, -1}, {{0, 2, 4}, {0, 0, 2}, {1, 1, 0}, {0, 2, 4}, {0, 2, 4}, {3, 2, 1}, {3, 2, 3}, {2, 1, 3}}}, {0.026029116478127282, 0.015661123128512717, 0.9402707805225143, 0.002312121009019687, 0.01572685886182604, 0.08455912123465786, 3.820834240654275e-6, 0.9019243895644184, 0.013493670452754881, 0.00001899791392827341, 0.0021947693796333604, 0.0011155261639424813, 9.322658852291926e-7, 0.0070087502658737815, 0.9896800219246652}},{{{0.2900645639262997, 0.05827514009756515, 0.8518649817786156, 0.8537191145195402, 0.5108449327990435, 0.44282081450170935, 0.7340350876509906, 0.16146910123228314, 0.08145420907687673, 0.8630921605385778, 0.564491750971316, 0.264677069167416, 0.05310359857656953, 0.3195515941629784, 0.23205619298792932, 0.7855187932396634, 0.4055760688349558, 0.33444274214456604, 0.8133354784610082, 0.6616801815216635, 0.6326059839342572, 0.9257699308608829, 0.9480716346286547, 0.5805791951586944}, {0.3425414200079575, 0.8674947907633178, 0.0962066528500392, 0.7268600806391542, 0.831696487208914, 0.4246739762616084}, {0.3621715651990486, 0.565390979406871, 0.7502422781320373}, {0.5615818157230306, 0.7976798142277326, 0.300713910239455, 0.6971386795554677, 0.24203022156005213, 0.5656236212398033, 0.5151951169997916, 0.2915626107205119, 0.9075874794154861, 0.7522881427787951, 0.8535149354781281, 0.6589566267862548, 0.9818175485546031, 0.8042165081501403, 0.2729357403194337, 0.3164152067782972, 0.11432275779128535, 0.7080098553001012, 0.5460756596802795, 0.4847187195693832, 0.6896487815296769, 0.34583829010105255, 0.9806846802734085, 0.734476441437346, 0.12806696580664642, 0.54815847587332, 0.6799707700339535, 0.037337761881878276, 0.8860367442465943, 0.9825348546335168}, {0.16477565303416195, 0.7457751511613664, 0.9784492648311083, 0.23024671185472162, 0.3112607175560339, 0.08681852437511162, 0.9966317162765052, 0.4260302037045813, 0.038324977236600215, 0.7704033175968144, 0.8823089584852197, 0.7180203484044801, 0.4922493175563207, 0.2856845980274312, 0.19266017695554283, 0.37218205830342754, 0.5115646372829121, 0.5512081565900852, 0.06459321114889639, 0.8240235824301075, 0.8315938672489587, 0.513870394708207, 0.1785564669023021, 0.8414887277965908, 0.6668182142147967, 0.7680952435468406, 0.20010720207119387, 0.6112420159418692, 0.35555749665876285, 0.6812767191717289}, {0.20347548579468877, 0.18521181223728797, 0.31723251942216263, 0.9108734015749146, 0.321166527309469}, {-1, 4, 4}, {{1, 2, 1}, {3, 1, 2}, {0, 1, 2}, {2, 2, 4}, {3, 1, 2}, {1, 0, 0}, {1, 0, 0}, {3, 2, 2}}}, {0.9953385016091594, 0.001193214318238978, 0.0001795210707191379, 0.0001995818084372676, 0.0030891811934451396, 5.066183830221487e-9, 6.18602755891509e-9, 0.9641985847191106, 1.353200404273094e-11, 0.03580140401514598, 3.4975012535422014e-10, 1.359714608744929e-6, 9.173001724803621e-7, 2.770899780282301e-13, 0.9999977226351915}}};

  for (unsigned int i = 0; i < sizeof (data) / sizeof (data[0]); ++i)
    {
      float pz[3*5];

      for (unsigned int j = 0; j < 3*5; ++j) { pz[j] = drand48 (); }

      estep (data[i].inputs.loga,
             // 4,
             6,
             // data[i].inputs.gamma,
             data[i].inputs.logbeta,
             3,
             data[i].inputs.c,
             5,
             data[i].inputs.d,
             pz,
             data[i].inputs.priorz,
             data[i].inputs.clamp,
             data[i].inputs.ratings,
             8);


      for (unsigned int j = 0; j < 3*5; ++j)
        {
          assert (fabs (pz[j] - data[i].pz[j]) <=
                  1e-4 * (1 + fabs (pz[j]) + fabs (data[i].pz[j])) ||
                  (fprintf (stderr, "%u: %g ?= %g\n", j, pz[j], data[i].pz[j]), 0));
        }
    }
}

int 
main (void)
{
  srand48 (69);

  test_estep ();

  return 0;
}
